package com.example.pixelyear.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.pixelyear.R
import com.example.pixelyear.bean.ColorBean
import com.example.pixelyear.utils.UIUtils
import com.example.pixelyear.utils.extension.*
import kotlinx.android.synthetic.main.item_add_date.view.*

class ColorAdapter(val context: Context) : BaseAdapter<ColorBean>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
        return BaseViewHolder(LayoutInflater.from(context).inflate(R.layout.item_add_date, parent, false))
    }

    override fun onBindView(itemView: View, bean: ColorBean, position: Int) {
        if (bean.color == -1) {
            itemView.Item_AddDate_Color.gone()
            itemView.Item_AddDate_Text.setTextColor(UIUtils.getColor(R.color.color_333333))
        } else {
            itemView.Item_AddDate_Color.visi()
            itemView.Item_AddDate_Color.setColor(bean.color)
            itemView.Item_AddDate_Text.setTextColor(bean.color)
        }

        if (bean.image == -1) {
            itemView.Item_AddDate_Img.gone()
        } else {
            itemView.Item_AddDate_Img.visi()
            itemView.Item_AddDate_Img.setImageResource(bean.image)
        }

        itemView.Item_AddDate_Text.text = bean.text
        itemView.setOnDoubleClickListener {
            onItemClick?.click(bean, position)
        }
    }

}
